from typing import *
from leetcode.editor.common.node import *


# leetcode submit region begin(Prohibit modification and deletion)
class Solution:
    def equalSubstring(self, s: str, t: str, maxCost: int) -> int:
        ans = 0
        left = 0
        window = 0
        for  right,item in enumerate(s):
            window+=abs(ord(item)-ord(t[right]))
            if window <= maxCost:
                ans = max(ans,right-left+1)
            while window > maxCost:
                window-=abs(ord(s[left])-ord(t[left]))
                left += 1
                if window <= maxCost:
                    ans = max(ans,right-left+1)

        return ans
# leetcode submit region end(Prohibit modification and deletion)


if __name__ == '__main__':
    solution = Solution()
    print(solution.equalSubstring("abcd","cdef",3))
    # your test code here